package GUI;

import Arbori.*;
import Visitor.*;

public class DerivareCalculField implements Command {
	private ArboreFunctional a;
	private ArboreFunctional stareA;
	private String stareText;
	private javax.swing.JTextField textDerivareCalcul;

	public DerivareCalculField(ArboreFunctional a, javax.swing.JTextField tdc) {
		this.a = a;
		this.textDerivareCalcul = tdc;
	}

	public ArboreFunctional execute() {
		getStare();
		Visitor derivVisitor = new DerivareCalculVisitor();
		a.acceptVisitor(derivVisitor);
		textDerivareCalcul.setText(Double
				.toString(((DerivareCalculVisitor) derivVisitor).getCalcul()));
		return a;
	}

	public String getErr() {
		return "";
	}

	public void getStare() {
		this.stareA = a;
		this.stareText = textDerivareCalcul.getText();
	}

	public ArboreFunctional unexecute() {
		this.a = stareA;
		textDerivareCalcul.setText(stareText);
		return a;
	}

	public void update(ArboreFunctional af) {
		this.a = af;
	}

}
